How to get an array of months in c#

46

How to get an array of months in c# -

var months = new string[12]; 
for (var month = 1; month <= 12; month++)
{
	var firstDay = new DateTime(DateTime.Now.Year, month, 1);
  	var name = firstDay.ToString("MMMM", CultureInfo.CreateSpecificCulture("en"));
  	months[month - 1] = name;
}

foreach (var month in months) 
{
	Console.WriteLine($"-> {month}");
}

find month number from date C# -

string name = DateTime.ParseExact("01/21/2014", "MM/dd/yyyy", null).ToString("MMMM"); //January

Comments

Submit
0 Comments